import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/12 9:50
 * @description 二分查找
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] re = {5,3,0,6,4,9,10,7,2,8};
        solution.maximumRemovals("qobftgcueho", "obue", re);
    }
    public int maximumRemovals(String s, String p, int[] removable) {
        int l = 0, r = removable.length, ans = -1;
        while (l <= r) {
            int mid = (l + r) / 2;
            // 表示该单词是否被移除
            boolean[] state = new boolean[s.length()];
            for (int i = 0; i < mid; i++) {
                state[removable[i]] = true;
            }
            if(check(s, p, state)) {
                ans = mid;
                l = mid + 1;
            }else {
                r = mid - 1;
            }
        }
        return ans;
    }
    public boolean check(String s, String p, boolean[] state) {
        int m = s.length(), n = p.length();
        if (m < n) {
            return false;
        }
        int l = 0, r = 0;
        while (r < n && l < m) {
            if (s.charAt(l) == p.charAt(r) && !state[l]) {
                r++;
            }
            l++;
        }
        return r == n;
    }
}
